//
//  AIPersonalListCell.m
//  Mia
//
//  Created by Vill on 2024/1/17.
//

#import "AIPersonalListCell.h"

@interface AIPersonalListCell ()

@property (nonatomic, strong) UIView *bgView;

@end


@implementation AIPersonalListCell

- (instancetype)initWithFrame:(CGRect)frame{
    if(self == [super initWithFrame:frame]){
        [self addSubview:self.bgView];
        [self.bgView addSubview:self.titleLbl];
        [self.bgView addSubview:self.arrowImg];
        [self.bgView addSubview:self.bgButton];
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(self);
        }];
        [self.titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(self.bgView).mas_offset(PTW(25));
            make.centerY.mas_equalTo(self);
        }];
        [self.arrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(PTW(12));
            make.trailing.mas_equalTo(self.bgView).mas_offset(-PTW(10));
            make.centerY.mas_equalTo(self.bgView);
        }];
        [self.bgButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(self.bgView);
        }];
    }
    return self;
}

- (UIView *)bgView{
    if(!_bgView){
        _bgView = [UIView new];
        _bgView.backgroundColor = UIColor.whiteColor;
        _bgView.layer.cornerRadius = PTW(10);
        _bgView.layer.masksToBounds = YES;
    }
    return _bgView;
}

- (UILabel *)titleLbl{
    if(!_titleLbl){
        _titleLbl = [UILabel new];
        _titleLbl.font = [UIFont fontWithWeight:Regular size:PTW(15)];
    }
    return _titleLbl;
}

- (UIImageView *)arrowImg{
    if(!_arrowImg){
        _arrowImg = [UIImageView new];
        _arrowImg.image = KImaged(@"ai_setting_jiantou");
    }
    return _arrowImg;
}

- (UIButton *)bgButton{
    if(!_bgButton){
        _bgButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_bgButton addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _bgButton;
}

-(void)btnAction:(UIButton *)sender{
    sender.selected = !sender.selected;
    if (sender.selected){
        // 如果箭头未旋转，则进行旋转
        [UIView animateWithDuration:0.3 animations:^{
            self.arrowImg.transform = CGAffineTransformMakeRotation(M_PI_2);
        }];
    }else{
        [UIView animateWithDuration:0.3 animations:^{
            self.arrowImg.transform = CGAffineTransformIdentity;
        }];
    }
}

@end
